<!-- commons/_tab_transacoes -->
<% if transacoes and transacoes.empty? %>
	<%= bootstrap_alert do %>
		<p>Nenhuma transação efetuada</p>
	<% end %>
<% end %>

<% if transacoes and transacoes.any? %>
	<fieldset>
		<legend>Transações</legend>

		<table class="table table-striped">
			<thead>
				<tr>
					<th>Data</th>
					<th>Observação</th>
					<th>Valor</th>
					<th>Tipo</th>
					<th></th>
					<th></th>
				</tr>
			</thead>

			<tbody>
				<% total = 0 %>
				<% transacoes.each do |t| %>
					<tr class="<%= t.fator_transacao == 1 ? 'credito' : 'debito' %>">
						<td class="text-center"><%= t.data.strftime("%d/%m/%Y") %></td>
						<td><%= t.observacao %></td>
						<td class="text-center"><%= number_to_currency t.valor %></td>
						<td class="text-center">
							<%= t.tipo_transacao %>
						</td>
						<td class="text-center span1">
							<%= link_to icon_edit,
								polymorphic_path(t, :action => "edit"),
								:class => "btn" %>
						</td>
						<td class="text-center span1">
							<%= link_to icon_remove,
								polymorphic_path(t, :action => "delete"),
								:class => "btn" %>
						</td>
					</tr>
					<% total += (t.valor.to_f * t.fator_transacao) %>
				<% end %>
			</tbody>

			<tfoot>
				<tr>
					<td class="text-right bold" colspan="2"><strong>Saldo:</strong></td>
					<td class="text-center">
						<strong class="<%= total >= 0 ? 'credito' : 'debito' %>"><%= number_to_currency total %></strong>
					</td>
					<td colspan="3"></td>
				</tr>
			</tfoot>

		</table>
	</fieldset>
<% end %>

